SlideShare a Scribd company logo
1 of 16
Class No.26  Data Structures http://ecomputernotes.com
Heap code in C++ template <class eType> void Heap<eType>::deleteMin( eType & minItem ) { if( isEmpty( ) ) { cout <<  &quot; heap is empty. “ << endl ; return; } minItem = array[ 1 ]; array[ 1 ] = array[ currentSize-- ]; percolateDown( 1 ); } http://ecomputernotes.com
Heap code in C++ //  hole is the index at which the percolate begins. template <class eType> void Heap<eType>::percolateDown( int hole ) { int child; eType tmp = array[ hole ]; for( ; hole * 2 <= currentSize; hole = child ) { child = hole * 2; if( child != currentSize &&  array[child+1] < array[ child ] ) child++;  //  right child is smaller if( array[ child ] < tmp ) array[ hole ] = array[ child ]; else break; } array[ hole ] = tmp; } http://ecomputernotes.com
Heap code in C++ template <class eType> const eType& Heap<eType>::getMin( ) { if( !isEmpty( ) ) return array[ 1 ]; } template <class eType> void Heap<eType>::buildHeap(eType* anArray, int n ) { for(int i = 1; i <= n; i++)  array[i] = anArray[i-1]; currentSize = n;  for( int i = currentSize / 2; i > 0; i-- ) percolateDown( i ); } http://ecomputernotes.com
Heap code in C++ template <class eType> bool Heap<eType>::isEmpty( ) { return currentSize == 0; } template <class eType> bool Heap<eType>::isFull( ) { return currentSize == capacity; } template <class eType> int Heap<eType>::getSize( ) { return currentSize; } http://ecomputernotes.com
BuildHeap in Linear Time ,[object Object],[object Object],[object Object],http://ecomputernotes.com
BuildHeap in Linear Time It is easy to see that this tree consists of (2 0 ) node at height  h , 2 1  nodes at height  h  –1, 2 2  at  h- 2   and, in general, 2 i  nodes at  h – i. http://ecomputernotes.com
Complete Binary Tree A B h  : 2 0  nodes H D I E J K C L F M G N O h  -1: 2 1  nodes h  -2: 2 2  nodes h  -3: 2 3  nodes http://ecomputernotes.com
BuildHeap in Linear Time The sum of the heights of all the nodes is then S   =    2 i ( h – i ), for  i  = 0 to  h-1 =  h + 2(h-1) + 4(h-2) + 8(h-3)+ ….. + 2 h-1  (1) Multiplying by 2 gives the equation 2S = 2 h + 4(h-1) + 8(h-2) + 16(h-3)+ ….. + 2 h  (2) Subtract the two equations to get S = - h + 2 + 4 + 8 + 16+ ….. + 2 h-1  +2 h = (2 h+1  – 1) - (h+1) Which proves the theorem. http://ecomputernotes.com
BuildHeap in Linear Time Since a complete binary tree has between  2 h  and   2 h+1  nodes S  = (2 h+1  – 1) - (h+1)   N  -  log 2 (N+1)  Clearly, as  N  gets larger, the log 2 ( N  +1) term becomes insignificant and S becomes a function of  N . http://ecomputernotes.com
BuildHeap in Linear Time ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],http://ecomputernotes.com
Height 1 Nodes Marking the left edges for height 1 nodes http://ecomputernotes.com
Height 2 Nodes Marking the first left edge and the subsequent right edge for height 2 nodes http://ecomputernotes.com
Height 3 Nodes Marking the first left edge and the subsequent two right edges for height 3 nodes http://ecomputernotes.com
Height 4 Nodes Marking the first left edge and the subsequent three right edges for height 4 nodes http://ecomputernotes.com
Theorem N=31, treeEdges=30, H=4, dottedEdges=4 (H). Darkened Edges = 26 = N-H-1 (31-4-1) http://ecomputernotes.com

More Related Content

What's hot

CS 210 Project UML
CS 210 Project UMLCS 210 Project UML
CS 210 Project UMLSharonYang50
 
IGraph a tool to analyze your network
IGraph a tool to analyze your networkIGraph a tool to analyze your network
IGraph a tool to analyze your networkPushpendra Tiwari
 
Rational number revision
Rational number revisionRational number revision
Rational number revisionShivani Sharma
 
Mini project title prime number generator
Mini project title prime number generatorMini project title prime number generator
Mini project title prime number generatorMd. Asad Chowdhury Dipu
 
Public class arithmetic operatordemo
Public class arithmetic operatordemoPublic class arithmetic operatordemo
Public class arithmetic operatordemoCliff Rodrigo
 
Analysis of different bit carry look ahead adder using verilog code 2
Analysis of different bit carry look ahead adder using verilog code 2Analysis of different bit carry look ahead adder using verilog code 2
Analysis of different bit carry look ahead adder using verilog code 2IAEME Publication
 
Ripple look-ahead-header
Ripple look-ahead-headerRipple look-ahead-header
Ripple look-ahead-headerAbid Ali
 
carry look ahead adder
carry look ahead addercarry look ahead adder
carry look ahead adderASHISH MANI
 
Linked list Output tracing
Linked list Output tracingLinked list Output tracing
Linked list Output tracingSamsil Arefin
 
C mcq practice test 2
C mcq practice test 2C mcq practice test 2
C mcq practice test 2Aman Kamboj
 
Lisp programming
Lisp programmingLisp programming
Lisp programmingilias ahmed
 
Hello world program
Hello world programHello world program
Hello world programSpy Seat
 
Introduction to cython: example of GCoptimization
Introduction to cython: example of GCoptimizationIntroduction to cython: example of GCoptimization
Introduction to cython: example of GCoptimizationKevin Keraudren
 

What's hot (19)

CS 210 Project UML
CS 210 Project UMLCS 210 Project UML
CS 210 Project UML
 
IGraph a tool to analyze your network
IGraph a tool to analyze your networkIGraph a tool to analyze your network
IGraph a tool to analyze your network
 
35th 36th Lecture
35th 36th Lecture35th 36th Lecture
35th 36th Lecture
 
Rational number revision
Rational number revisionRational number revision
Rational number revision
 
Mini project title prime number generator
Mini project title prime number generatorMini project title prime number generator
Mini project title prime number generator
 
Public class arithmetic operatordemo
Public class arithmetic operatordemoPublic class arithmetic operatordemo
Public class arithmetic operatordemo
 
Derivadas
DerivadasDerivadas
Derivadas
 
07f03 carryskip
07f03 carryskip07f03 carryskip
07f03 carryskip
 
Space complexity
Space complexitySpace complexity
Space complexity
 
Analysis of different bit carry look ahead adder using verilog code 2
Analysis of different bit carry look ahead adder using verilog code 2Analysis of different bit carry look ahead adder using verilog code 2
Analysis of different bit carry look ahead adder using verilog code 2
 
Ripple look-ahead-header
Ripple look-ahead-headerRipple look-ahead-header
Ripple look-ahead-header
 
carry look ahead adder
carry look ahead addercarry look ahead adder
carry look ahead adder
 
Thesis PPT
Thesis PPTThesis PPT
Thesis PPT
 
Linked list Output tracing
Linked list Output tracingLinked list Output tracing
Linked list Output tracing
 
C mcq practice test 2
C mcq practice test 2C mcq practice test 2
C mcq practice test 2
 
Lisp programming
Lisp programmingLisp programming
Lisp programming
 
Hello world program
Hello world programHello world program
Hello world program
 
Introduction to cython: example of GCoptimization
Introduction to cython: example of GCoptimizationIntroduction to cython: example of GCoptimization
Introduction to cython: example of GCoptimization
 
Practical no 3
Practical no 3Practical no 3
Practical no 3
 

Viewers also liked

computer notes - Data Structures - 18
computer notes - Data Structures - 18computer notes - Data Structures - 18
computer notes - Data Structures - 18ecomputernotes
 
computer notes - Data Structures - 2
computer notes - Data Structures - 2computer notes - Data Structures - 2
computer notes - Data Structures - 2ecomputernotes
 
computer notes - Data Structures - 25
computer notes - Data Structures - 25computer notes - Data Structures - 25
computer notes - Data Structures - 25ecomputernotes
 
computer notes - Deleting a node
computer notes - Deleting a nodecomputer notes - Deleting a node
computer notes - Deleting a nodeecomputernotes
 
computer notes - Data Structures - 23
computer notes - Data Structures - 23computer notes - Data Structures - 23
computer notes - Data Structures - 23ecomputernotes
 
computer notes - Data Structures - 24
computer notes - Data Structures - 24computer notes - Data Structures - 24
computer notes - Data Structures - 24ecomputernotes
 
computer notes - Data Structures - 16
computer notes - Data Structures - 16computer notes - Data Structures - 16
computer notes - Data Structures - 16ecomputernotes
 
computer notes - Data Structures - 31
computer notes - Data Structures - 31computer notes - Data Structures - 31
computer notes - Data Structures - 31ecomputernotes
 
computer notes - Data Structures - 34
computer notes - Data Structures - 34computer notes - Data Structures - 34
computer notes - Data Structures - 34ecomputernotes
 
computer notes - Data Structures - 5
computer notes - Data Structures - 5computer notes - Data Structures - 5
computer notes - Data Structures - 5ecomputernotes
 
computer notes - Data Structures - 32
computer notes - Data Structures - 32computer notes - Data Structures - 32
computer notes - Data Structures - 32ecomputernotes
 
computer notes - Data Structures - 6
computer notes - Data Structures - 6computer notes - Data Structures - 6
computer notes - Data Structures - 6ecomputernotes
 
computer notes - Data Structures - 21
computer notes - Data Structures - 21computer notes - Data Structures - 21
computer notes - Data Structures - 21ecomputernotes
 
computer notes - Data Structures - 29
computer notes - Data Structures - 29computer notes - Data Structures - 29
computer notes - Data Structures - 29ecomputernotes
 
computer notes - Data Structures - 22
computer notes - Data Structures - 22computer notes - Data Structures - 22
computer notes - Data Structures - 22ecomputernotes
 
computer notes - Data Structures - 12
computer notes - Data Structures - 12computer notes - Data Structures - 12
computer notes - Data Structures - 12ecomputernotes
 
computer notes - Data Structures - 14
computer notes - Data Structures - 14computer notes - Data Structures - 14
computer notes - Data Structures - 14ecomputernotes
 
computer notes - Data Structures - 20
computer notes - Data Structures - 20computer notes - Data Structures - 20
computer notes - Data Structures - 20ecomputernotes
 
computer notes - Data Structures - 4
computer notes - Data Structures - 4computer notes - Data Structures - 4
computer notes - Data Structures - 4ecomputernotes
 
computer notes - Data Structures - 7
computer notes - Data Structures - 7computer notes - Data Structures - 7
computer notes - Data Structures - 7ecomputernotes
 

Viewers also liked (20)

computer notes - Data Structures - 18
computer notes - Data Structures - 18computer notes - Data Structures - 18
computer notes - Data Structures - 18
 
computer notes - Data Structures - 2
computer notes - Data Structures - 2computer notes - Data Structures - 2
computer notes - Data Structures - 2
 
computer notes - Data Structures - 25
computer notes - Data Structures - 25computer notes - Data Structures - 25
computer notes - Data Structures - 25
 
computer notes - Deleting a node
computer notes - Deleting a nodecomputer notes - Deleting a node
computer notes - Deleting a node
 
computer notes - Data Structures - 23
computer notes - Data Structures - 23computer notes - Data Structures - 23
computer notes - Data Structures - 23
 
computer notes - Data Structures - 24
computer notes - Data Structures - 24computer notes - Data Structures - 24
computer notes - Data Structures - 24
 
computer notes - Data Structures - 16
computer notes - Data Structures - 16computer notes - Data Structures - 16
computer notes - Data Structures - 16
 
computer notes - Data Structures - 31
computer notes - Data Structures - 31computer notes - Data Structures - 31
computer notes - Data Structures - 31
 
computer notes - Data Structures - 34
computer notes - Data Structures - 34computer notes - Data Structures - 34
computer notes - Data Structures - 34
 
computer notes - Data Structures - 5
computer notes - Data Structures - 5computer notes - Data Structures - 5
computer notes - Data Structures - 5
 
computer notes - Data Structures - 32
computer notes - Data Structures - 32computer notes - Data Structures - 32
computer notes - Data Structures - 32
 
computer notes - Data Structures - 6
computer notes - Data Structures - 6computer notes - Data Structures - 6
computer notes - Data Structures - 6
 
computer notes - Data Structures - 21
computer notes - Data Structures - 21computer notes - Data Structures - 21
computer notes - Data Structures - 21
 
computer notes - Data Structures - 29
computer notes - Data Structures - 29computer notes - Data Structures - 29
computer notes - Data Structures - 29
 
computer notes - Data Structures - 22
computer notes - Data Structures - 22computer notes - Data Structures - 22
computer notes - Data Structures - 22
 
computer notes - Data Structures - 12
computer notes - Data Structures - 12computer notes - Data Structures - 12
computer notes - Data Structures - 12
 
computer notes - Data Structures - 14
computer notes - Data Structures - 14computer notes - Data Structures - 14
computer notes - Data Structures - 14
 
computer notes - Data Structures - 20
computer notes - Data Structures - 20computer notes - Data Structures - 20
computer notes - Data Structures - 20
 
computer notes - Data Structures - 4
computer notes - Data Structures - 4computer notes - Data Structures - 4
computer notes - Data Structures - 4
 
computer notes - Data Structures - 7
computer notes - Data Structures - 7computer notes - Data Structures - 7
computer notes - Data Structures - 7
 

Similar to computer notes - Data Structures - 26

Python for Scientific Computing
Python for Scientific ComputingPython for Scientific Computing
Python for Scientific ComputingAlbert DeFusco
 
Introduction to data structures and complexity.pptx
Introduction to data structures and complexity.pptxIntroduction to data structures and complexity.pptx
Introduction to data structures and complexity.pptxPJS KUMAR
 
01 - DAA - PPT.pptx
01 - DAA - PPT.pptx01 - DAA - PPT.pptx
01 - DAA - PPT.pptxKokilaK25
 
lecture 4
lecture 4lecture 4
lecture 4sajinsc
 
Classical programming interview questions
Classical programming interview questionsClassical programming interview questions
Classical programming interview questionsGradeup
 
computer notes - Data Structures - 8
computer notes - Data Structures - 8computer notes - Data Structures - 8
computer notes - Data Structures - 8ecomputernotes
 
Basic Computer Engineering Unit II as per RGPV Syllabus
Basic Computer Engineering Unit II as per RGPV SyllabusBasic Computer Engineering Unit II as per RGPV Syllabus
Basic Computer Engineering Unit II as per RGPV SyllabusNANDINI SHARMA
 
Computer notes - Hashing
Computer notes - HashingComputer notes - Hashing
Computer notes - Hashingecomputernotes
 
Data Structure & Algorithms - Mathematical
Data Structure & Algorithms - MathematicalData Structure & Algorithms - Mathematical
Data Structure & Algorithms - Mathematicalbabuk110
 
lecture 5
lecture 5lecture 5
lecture 5sajinsc
 
lecture 6
lecture 6lecture 6
lecture 6sajinsc
 
module1_Introductiontoalgorithms_2022.pdf
module1_Introductiontoalgorithms_2022.pdfmodule1_Introductiontoalgorithms_2022.pdf
module1_Introductiontoalgorithms_2022.pdfShiwani Gupta
 
C Programming Interview Questions
C Programming Interview QuestionsC Programming Interview Questions
C Programming Interview QuestionsGradeup
 
Lecture 12 intermediate code generation
Lecture 12 intermediate code generationLecture 12 intermediate code generation
Lecture 12 intermediate code generationIffat Anjum
 
computer notes - Data Structures - 35
computer notes - Data Structures - 35computer notes - Data Structures - 35
computer notes - Data Structures - 35ecomputernotes
 

Similar to computer notes - Data Structures - 26 (20)

Python for Scientific Computing
Python for Scientific ComputingPython for Scientific Computing
Python for Scientific Computing
 
Introduction to data structures and complexity.pptx
Introduction to data structures and complexity.pptxIntroduction to data structures and complexity.pptx
Introduction to data structures and complexity.pptx
 
01 - DAA - PPT.pptx
01 - DAA - PPT.pptx01 - DAA - PPT.pptx
01 - DAA - PPT.pptx
 
lecture 4
lecture 4lecture 4
lecture 4
 
Q
QQ
Q
 
Classical programming interview questions
Classical programming interview questionsClassical programming interview questions
Classical programming interview questions
 
Chapter 10 ds
Chapter 10 dsChapter 10 ds
Chapter 10 ds
 
computer notes - Data Structures - 8
computer notes - Data Structures - 8computer notes - Data Structures - 8
computer notes - Data Structures - 8
 
Basic Computer Engineering Unit II as per RGPV Syllabus
Basic Computer Engineering Unit II as per RGPV SyllabusBasic Computer Engineering Unit II as per RGPV Syllabus
Basic Computer Engineering Unit II as per RGPV Syllabus
 
Computer notes - Hashing
Computer notes - HashingComputer notes - Hashing
Computer notes - Hashing
 
Data Structure & Algorithms - Mathematical
Data Structure & Algorithms - MathematicalData Structure & Algorithms - Mathematical
Data Structure & Algorithms - Mathematical
 
Ch8a
Ch8aCh8a
Ch8a
 
Apriori algorithm
Apriori algorithmApriori algorithm
Apriori algorithm
 
lecture 5
lecture 5lecture 5
lecture 5
 
Lecture 1
Lecture 1Lecture 1
Lecture 1
 
lecture 6
lecture 6lecture 6
lecture 6
 
module1_Introductiontoalgorithms_2022.pdf
module1_Introductiontoalgorithms_2022.pdfmodule1_Introductiontoalgorithms_2022.pdf
module1_Introductiontoalgorithms_2022.pdf
 
C Programming Interview Questions
C Programming Interview QuestionsC Programming Interview Questions
C Programming Interview Questions
 
Lecture 12 intermediate code generation
Lecture 12 intermediate code generationLecture 12 intermediate code generation
Lecture 12 intermediate code generation
 
computer notes - Data Structures - 35
computer notes - Data Structures - 35computer notes - Data Structures - 35
computer notes - Data Structures - 35
 

More from ecomputernotes

computer notes - Data Structures - 30
computer notes - Data Structures - 30computer notes - Data Structures - 30
computer notes - Data Structures - 30ecomputernotes
 
computer notes - Data Structures - 39
computer notes - Data Structures - 39computer notes - Data Structures - 39
computer notes - Data Structures - 39ecomputernotes
 
computer notes - Data Structures - 11
computer notes - Data Structures - 11computer notes - Data Structures - 11
computer notes - Data Structures - 11ecomputernotes
 
computer notes - Data Structures - 15
computer notes - Data Structures - 15computer notes - Data Structures - 15
computer notes - Data Structures - 15ecomputernotes
 
Computer notes - Including Constraints
Computer notes - Including ConstraintsComputer notes - Including Constraints
Computer notes - Including Constraintsecomputernotes
 
Computer notes - Date time Functions
Computer notes - Date time FunctionsComputer notes - Date time Functions
Computer notes - Date time Functionsecomputernotes
 
Computer notes - Subqueries
Computer notes - SubqueriesComputer notes - Subqueries
Computer notes - Subqueriesecomputernotes
 
Computer notes - Other Database Objects
Computer notes - Other Database ObjectsComputer notes - Other Database Objects
Computer notes - Other Database Objectsecomputernotes
 
computer notes - Data Structures - 28
computer notes - Data Structures - 28computer notes - Data Structures - 28
computer notes - Data Structures - 28ecomputernotes
 
computer notes - Data Structures - 19
computer notes - Data Structures - 19computer notes - Data Structures - 19
computer notes - Data Structures - 19ecomputernotes
 
computer notes - Data Structures - 13
computer notes - Data Structures - 13computer notes - Data Structures - 13
computer notes - Data Structures - 13ecomputernotes
 
Computer notes - Advanced Subqueries
Computer notes -   Advanced SubqueriesComputer notes -   Advanced Subqueries
Computer notes - Advanced Subqueriesecomputernotes
 
Computer notes - Aggregating Data Using Group Functions
Computer notes - Aggregating Data Using Group FunctionsComputer notes - Aggregating Data Using Group Functions
Computer notes - Aggregating Data Using Group Functionsecomputernotes
 
computer notes - Data Structures - 36
computer notes - Data Structures - 36computer notes - Data Structures - 36
computer notes - Data Structures - 36ecomputernotes
 
Computer notes - Enhancements to the GROUP BY Clause
Computer notes - Enhancements to the GROUP BY ClauseComputer notes - Enhancements to the GROUP BY Clause
Computer notes - Enhancements to the GROUP BY Clauseecomputernotes
 
Computer notes - Manipulating Data
Computer notes - Manipulating DataComputer notes - Manipulating Data
Computer notes - Manipulating Dataecomputernotes
 
Computer notes - Writing Basic SQL SELECT Statements
Computer notes - Writing Basic SQL SELECT StatementsComputer notes - Writing Basic SQL SELECT Statements
Computer notes - Writing Basic SQL SELECT Statementsecomputernotes
 
computer notes - Data Structures - 10
computer notes - Data Structures - 10computer notes - Data Structures - 10
computer notes - Data Structures - 10ecomputernotes
 
Computer notes - Controlling User Access
Computer notes - Controlling User AccessComputer notes - Controlling User Access
Computer notes - Controlling User Accessecomputernotes
 
Computer notes - Using SET Operator
Computer notes - Using SET OperatorComputer notes - Using SET Operator
Computer notes - Using SET Operatorecomputernotes
 

More from ecomputernotes (20)

computer notes - Data Structures - 30
computer notes - Data Structures - 30computer notes - Data Structures - 30
computer notes - Data Structures - 30
 
computer notes - Data Structures - 39
computer notes - Data Structures - 39computer notes - Data Structures - 39
computer notes - Data Structures - 39
 
computer notes - Data Structures - 11
computer notes - Data Structures - 11computer notes - Data Structures - 11
computer notes - Data Structures - 11
 
computer notes - Data Structures - 15
computer notes - Data Structures - 15computer notes - Data Structures - 15
computer notes - Data Structures - 15
 
Computer notes - Including Constraints
Computer notes - Including ConstraintsComputer notes - Including Constraints
Computer notes - Including Constraints
 
Computer notes - Date time Functions
Computer notes - Date time FunctionsComputer notes - Date time Functions
Computer notes - Date time Functions
 
Computer notes - Subqueries
Computer notes - SubqueriesComputer notes - Subqueries
Computer notes - Subqueries
 
Computer notes - Other Database Objects
Computer notes - Other Database ObjectsComputer notes - Other Database Objects
Computer notes - Other Database Objects
 
computer notes - Data Structures - 28
computer notes - Data Structures - 28computer notes - Data Structures - 28
computer notes - Data Structures - 28
 
computer notes - Data Structures - 19
computer notes - Data Structures - 19computer notes - Data Structures - 19
computer notes - Data Structures - 19
 
computer notes - Data Structures - 13
computer notes - Data Structures - 13computer notes - Data Structures - 13
computer notes - Data Structures - 13
 
Computer notes - Advanced Subqueries
Computer notes -   Advanced SubqueriesComputer notes -   Advanced Subqueries
Computer notes - Advanced Subqueries
 
Computer notes - Aggregating Data Using Group Functions
Computer notes - Aggregating Data Using Group FunctionsComputer notes - Aggregating Data Using Group Functions
Computer notes - Aggregating Data Using Group Functions
 
computer notes - Data Structures - 36
computer notes - Data Structures - 36computer notes - Data Structures - 36
computer notes - Data Structures - 36
 
Computer notes - Enhancements to the GROUP BY Clause
Computer notes - Enhancements to the GROUP BY ClauseComputer notes - Enhancements to the GROUP BY Clause
Computer notes - Enhancements to the GROUP BY Clause
 
Computer notes - Manipulating Data
Computer notes - Manipulating DataComputer notes - Manipulating Data
Computer notes - Manipulating Data
 
Computer notes - Writing Basic SQL SELECT Statements
Computer notes - Writing Basic SQL SELECT StatementsComputer notes - Writing Basic SQL SELECT Statements
Computer notes - Writing Basic SQL SELECT Statements
 
computer notes - Data Structures - 10
computer notes - Data Structures - 10computer notes - Data Structures - 10
computer notes - Data Structures - 10
 
Computer notes - Controlling User Access
Computer notes - Controlling User AccessComputer notes - Controlling User Access
Computer notes - Controlling User Access
 
Computer notes - Using SET Operator
Computer notes - Using SET OperatorComputer notes - Using SET Operator
Computer notes - Using SET Operator
 

Recently uploaded

"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 

Recently uploaded (20)

"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 

computer notes - Data Structures - 26

  • 1. Class No.26 Data Structures http://ecomputernotes.com
  • 2. Heap code in C++ template <class eType> void Heap<eType>::deleteMin( eType & minItem ) { if( isEmpty( ) ) { cout << &quot; heap is empty. “ << endl ; return; } minItem = array[ 1 ]; array[ 1 ] = array[ currentSize-- ]; percolateDown( 1 ); } http://ecomputernotes.com
  • 3. Heap code in C++ // hole is the index at which the percolate begins. template <class eType> void Heap<eType>::percolateDown( int hole ) { int child; eType tmp = array[ hole ]; for( ; hole * 2 <= currentSize; hole = child ) { child = hole * 2; if( child != currentSize && array[child+1] < array[ child ] ) child++; // right child is smaller if( array[ child ] < tmp ) array[ hole ] = array[ child ]; else break; } array[ hole ] = tmp; } http://ecomputernotes.com
  • 4. Heap code in C++ template <class eType> const eType& Heap<eType>::getMin( ) { if( !isEmpty( ) ) return array[ 1 ]; } template <class eType> void Heap<eType>::buildHeap(eType* anArray, int n ) { for(int i = 1; i <= n; i++) array[i] = anArray[i-1]; currentSize = n; for( int i = currentSize / 2; i > 0; i-- ) percolateDown( i ); } http://ecomputernotes.com
  • 5. Heap code in C++ template <class eType> bool Heap<eType>::isEmpty( ) { return currentSize == 0; } template <class eType> bool Heap<eType>::isFull( ) { return currentSize == capacity; } template <class eType> int Heap<eType>::getSize( ) { return currentSize; } http://ecomputernotes.com
  • 6.
  • 7. BuildHeap in Linear Time It is easy to see that this tree consists of (2 0 ) node at height h , 2 1 nodes at height h –1, 2 2 at h- 2 and, in general, 2 i nodes at h – i. http://ecomputernotes.com
  • 8. Complete Binary Tree A B h : 2 0 nodes H D I E J K C L F M G N O h -1: 2 1 nodes h -2: 2 2 nodes h -3: 2 3 nodes http://ecomputernotes.com
  • 9. BuildHeap in Linear Time The sum of the heights of all the nodes is then S =  2 i ( h – i ), for i = 0 to h-1 = h + 2(h-1) + 4(h-2) + 8(h-3)+ ….. + 2 h-1 (1) Multiplying by 2 gives the equation 2S = 2 h + 4(h-1) + 8(h-2) + 16(h-3)+ ….. + 2 h (2) Subtract the two equations to get S = - h + 2 + 4 + 8 + 16+ ….. + 2 h-1 +2 h = (2 h+1 – 1) - (h+1) Which proves the theorem. http://ecomputernotes.com
  • 10. BuildHeap in Linear Time Since a complete binary tree has between 2 h and 2 h+1 nodes S = (2 h+1 – 1) - (h+1)  N - log 2 (N+1) Clearly, as N gets larger, the log 2 ( N +1) term becomes insignificant and S becomes a function of N . http://ecomputernotes.com
  • 11.
  • 12. Height 1 Nodes Marking the left edges for height 1 nodes http://ecomputernotes.com
  • 13. Height 2 Nodes Marking the first left edge and the subsequent right edge for height 2 nodes http://ecomputernotes.com
  • 14. Height 3 Nodes Marking the first left edge and the subsequent two right edges for height 3 nodes http://ecomputernotes.com
  • 15. Height 4 Nodes Marking the first left edge and the subsequent three right edges for height 4 nodes http://ecomputernotes.com
  • 16. Theorem N=31, treeEdges=30, H=4, dottedEdges=4 (H). Darkened Edges = 26 = N-H-1 (31-4-1) http://ecomputernotes.com

Editor's Notes

  1. End of lecture 31, start of 32
  2. End of lecture 32